import { createRouter, createWebHistory } from "vue-router";
const routerHistory = createWebHistory();


import Layout from "@/layout/index.vue";
export const constantRoutes = [
  {
    path: "/redirect",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "/redirect/:path(.*)",
        component: () => import("@/views/redirect/index"),
      },
    ],
  },
  {
    path: "/login",
    component: () => import("@/views/login/index"),
    hidden: true,
  },
  {
    path: "/auth-redirect",
    component: () => import("@/views/login/auth-redirect"),
    hidden: true,
  },
  {
    path: "/",
    component: Layout,
    redirect: "/index",
    meta: { title: "流程信息", icon: "house",activeMenu:'/' },
    children: [
      {
        path: "/index",
        component: () => import("@/views/dashboard/index"),
        name: "Index",
        meta: { title: "首页", icon: "house", affix: true,activeMenu:'/index' },
      },
      {
        path: "/flowEdit",
        name: "flowEdit",
        component: () => import("@/views/FlowDetail.vue"),
        hidden: true,
        meta: { 
          title: "流程编辑", 
          icon: "Box", 
          show: true, 
          isFrame: false,
          activeMenu:'/flowDetail',
          transition: 'slide'
        },
      },
      {
        path: "/flowAdd",
        name: "flowAdd",
        component: () => import("@/views/FlowDetail.vue"),
        hidden: true,
        meta: { 
          title: "流程添加", 
          icon: "Box", 
          show: true, 
          isFrame: false,
          activeMenu:'/flowDetail',
          transition: 'slide'
        },
      },
    ],
  },{
    path: "/flowList",
    component: Layout,
    redirect: "/flowList",
    meta: { title: "流程列表", icon: "list",activeMenu:'/' },
    children: [
      {
        path: "/flowList",
        component: () => import("@/views/flow/flow"),
        name: "flowList",
        meta: { title: "流程列表", icon: "list", affix: false,activeMenu:'/flowList' },
      },
    ]
  },
  {
    path: "/todoList",
    component: Layout,
    redirect: "/todoList",
    meta: { title: "我的待办", icon: "timer",activeMenu:'/' },
    children: [
      {
        path: "/todoList",
        component: () => import("@/views/flow/todo"),
        name: "todoList",
        meta: { title: "我的待办", icon: "timer", affix: false,activeMenu:'/todoList' },
      },
    ]
  },
  {
    path: "/doneList",
    component: Layout,
    redirect: "/doneList",
    meta: { title: "我的已办", icon: "documentAdd",activeMenu:'/' },
    children: [
      {
        path: "/doneList",
        component: () => import("@/views/flow/done"),
        name: "doneList",
        meta: { title: "我的已办", icon: "documentAdd", affix: false,activeMenu:'/doneList' },
      },
    ]
  },
  {
    path: "/ccList",
    component: Layout,
    redirect: "/ccList",
    meta: { title: "抄送我的", icon: "documentAdd",activeMenu:'/' },
    children: [
      {
        path: "/ccList",
        component: () => import("@/views/flow/cc"),
        name: "ccList",
        meta: { title: "抄送我的", icon: "documentAdd", affix: false,activeMenu:'/ccList' },
      },
    ]
  },
  {
    path: "/flowFrom",
    component: Layout,
    redirect: "/flowFrom",
    meta: { title: "流程表单", icon: "flow",activeMenu:'/' },
    children: [
      {
        path: "/flowFrom",
        component: () => import("@/views/FlowFrom"),
        name: "flowFrom",
        meta: { title: "流程表单", icon: "Document", affix: false ,activeMenu:'/flowFrom'},
      },
    ]
  }
];

const router = createRouter({
  history: routerHistory,
  routes:  constantRoutes,
  // 刷新时，滚动条位置还原
  scrollBehavior: () => ({ left: 0, top: 0 }),
  // scrollBehavior(to, from, savedPosition) {
  //   if (savedPosition) {
  //     return savedPosition
  //   } else {
  //     return { top: 0 }
  //   }
  // },
});
export default router;
